using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Presentation.Contracts;
using Presentation;

namespace ProjektZespolowy.Forum
	{
	public partial class ShowTopics : System.Web.UI.Page, IForumView
		{
		private TopicsPresenter presenter;


		protected override void OnInit(EventArgs e)
			{
			base.OnInit(e);
			presenter = new TopicsPresenter(this);
			}



		protected void Page_Load(object sender, EventArgs e)
			{
			if (!IsPostBack)
				{
				if (!string.IsNullOrEmpty(Request.QueryString["ForumID"]))
					ViewState["ForumID"] = Request.QueryString["ForumID"];
				presenter.Initialize();
				}

			}

		protected void deleteForumButton_Click(object sender, EventArgs e)
			{

			}

		protected void unsignForumButton_Click(object sender, EventArgs e)
			{

			}

		#region IForumView Members

		public void PageComments(int commentsPerPage, int howManyComments)
			{
			throw new Exception("The method or operation is not implemented.");
			}

		public void ShowComments(DataTable comments)
			{
			ViewState["tabelka"] = comments;
			GridView1.DataSource = ViewState["tabelka"];
			GridView1.DataBind();
			}

		public int ForumID
			{
			get
				{
				if (ViewState["ForumID"] != null)
					return Int32.Parse((string)ViewState["ForumID"]);
				else
					return -1;
				}
			}

		public int CommentsStartIndex
			{
			get { return 0; }
			}


		public bool deleteButtonVisible
			{
			set { this.deleteForumButton.Visible = value;
			GridView1.Columns[1].Visible = value;
			GridView1.Columns[4].Visible = value;
			GridView1.Columns[2].Visible = !value;
			GridView1.Columns[5].Visible = !value;
				}
			}

		public bool unsignButtonVisible
			{
			set { this.unsignForumButton.Visible = value; }
			}

		public bool newTopicButtonVisible
			{
			set { this.newTopicButton.Visible = value; }
			}

		#endregion

		#region IUserAuthView Members

		public int LoggedUserID
			{
			get
				{
				if (Session[Globals.ContentNamesGlobals.SessionWithUserId] != null)
					return Int32.Parse(Session[Globals.ContentNamesGlobals.SessionWithUserId].ToString());
				else
					return -1;
				}
			}

		#endregion

		protected void newTopicButton_Click(object sender, EventArgs e)
			{
			Panel3.Visible = true;
			//UpdatePanel1.Update();
			}

		public string ReplyLinkString(string binderString)
			{
			if (string.IsNullOrEmpty(binderString))
				return "";
			else
				return "Odpowiedz";
			}

		protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
			{
			GridView1.DataSource = ViewState["tabelka"];
			GridView1.PageIndex = e.NewPageIndex;
			GridView1.DataBind();
			}

		#region IForumView Members


		public int ParentCommentID
			{
			get { throw new Exception("The method or operation is not implemented."); }
			}

		#endregion

		protected void deleteForumButton_Click1(object sender, EventArgs e)
			{
			presenter.DeleteForum();
			Response.Redirect("~/Forum/Default.aspx");
			}

		protected void addTopicButton_Click(object sender, EventArgs e)
			{
			presenter.AddTopic(topicTextBox.Text, firstCommentTextBox.Text);
			presenter.Initialize();
			topicTextBox.Text = "";
			firstCommentTextBox.Text = "";
			Panel3.Visible = false;
			}

		protected void unsignForumButton_Click1(object sender, EventArgs e)
			{
			presenter.unsignFromForum();
			Response.Redirect("~/Forum/Default.aspx");
			}
		}
	}
